package com.farmcode.plugin.objectinfo.datasource.test;


import com.farmcode.api.plugin.objectinfo.ObjectInfoPluginManager;
import com.farmcode.plugin.objectinfo.datasource.FARMCodeDatabaseMetadata;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author oscar
 */
public class metadtadaNewClass {

    public static void main(String[] args) {
        try {
           
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/object_metadata", "root", "admin");
            FARMCodeDatabaseMetadata databaseMetadata = new FARMCodeDatabaseMetadata(connection);
            java.sql.ResultSet resultSet = databaseMetadata.getObjects("ugpp", new String[]{"TABLE"});
            while (resultSet.next()) {
                System.out.println(resultSet.getString("object_name") + ":");
                ResultSet childs = databaseMetadata.getObjectChilds("ugpp", resultSet.getString("object_name"), new String[]{"COLUMN"});
                while (childs.next()) {
                    System.out.println("\t" + childs.getString("object_name") + "[" + childs.getString("TYPE") + ", " + childs.getString("LENGTH") + "]");
                    ResultSet childs2 = databaseMetadata.getObjectChilds("ugpp", childs.getString("object_name"), new String[]{"COLUMN"});
                    while (childs2.next()) {
                        System.out.println("\t\t" + childs2.getString("object_name"));
                    }
                }
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(metadtadaNewClass.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(metadtadaNewClass.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
